package com.own.component.springdoc.config;

import com.own.component.springdoc.property.SwaggerProperty;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;

import javax.annotation.Resource;

/**
 * OpenApiConfig
 *
 * @author chenxueli
 * @date 2023-12-05 15:45:00
 */
@SpringBootConfiguration
public class OpenApiConfig {

    @Resource
    private SwaggerProperty swaggerProperty;

    @Bean
    protected OpenAPI apiInfo() {
        return new OpenAPI()
                .paths(null)
                .info(new Info()
                        .title(swaggerProperty.getTitle())
                        .description(swaggerProperty.getDescription())
                        .version(swaggerProperty.getVersion())
                        .contact(new Contact().name(swaggerProperty.getAuthor()).email(swaggerProperty.getEmail()).url(swaggerProperty.getUrl()))
                        .license(new License().name(swaggerProperty.getLicense()).url(swaggerProperty.getLicenseUrl()))
                );
    }

}
